package model
{
	import model.ApplicationView;
	import util.site.PartCodes;
	
	/**
	 * ...
	 * @author kasoi
	 */
	public class ApplicationModel 
	{
		
		//////////////////////////////////////////////////////////
		// Singleton initialization
		//////////////////////////////////////////////////////////
		
		private static var instance: ApplicationModel;
		
		private static var allowInstantation: Boolean = true;
		
		public static function getInstance() : ApplicationModel
		{
			if (!instance)
			{
				instance = new ApplicationModel();
				allowInstantation = false;
			}
			return instance;
		}
	   
		public function ApplicationModel() 
		{
			if (!ApplicationModel.allowInstantation)
			{
				throw new Error("Error: Instantiation failed.");
			}
		}
		
		
		
		
		//////////////////////////////////////////////////////////
		// Public properties
		//////////////////////////////////////////////////////////
		
		//////////////////////////////////////////////////////////
		// Private properties
		//////////////////////////////////////////////////////////
		
		private var isInitialized: Boolean = false;
		
		//////////////////////////////////////////////////////////
		// Public methods
		//////////////////////////////////////////////////////////
		
		public function init() : void 
		{
			if (this.isInitialized) throw new Error('ApplicationModel already initialized');
			this.isInitialized = true;
			
		}
		
		public function openPart(code: String) : void 
		{
			if (!PartCodes.contains(code)) return;
			ApplicationView.getInstance().partManager.changePart(code);
		}
		
	}
}